package biz.model;

import java.io.Serializable;
import java.sql.Timestamp;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.hibernate.annotations.GenericGenerator;

@Entity
@Table(name = "bbs_attachment")
public class BbsAttachment implements Serializable {

	private static final long serialVersionUID = 1L;
	private String id;
//	private String boardid;
	private BbsBoard attboard;
//	private String userid;
	private BbsUser attuser;
	private String path;
	private String filename;
	private Timestamp date;
//	private String postid;
	private BbsPost attpost;
	private int delmark;
	
	@Id
	@GeneratedValue(generator = "pk")
	@GenericGenerator(name = "pk", strategy = "uuid.hex")
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

//	public String getBoardid() {
//		return boardid;
//	}
//
//	public void setBoardid(String boardid) {
//		this.boardid = boardid;
//	}
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "boardid")
	public BbsBoard getAttboard() {
		return attboard;
	}

	public void setAttboard(BbsBoard attboard) {
		this.attboard = attboard;
	}

//	public String getUserid() {
//		return userid;
//	}
//
//	public void setUserid(String userid) {
//		this.userid = userid;
//	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "userid")
	public BbsUser getAttuser() {
		return attuser;
	}

	public void setAttuser(BbsUser attuser) {
		this.attuser = attuser;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public Timestamp getDate() {
		return date;
	}

	public void setDate(Timestamp date) {
		this.date = date;
	}

//	public String getPostid() {
//		return postid;
//	}
//
//	public void setPostid(String postid) {
//		this.postid = postid;
//	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "postid")
	public BbsPost getAttpost() {
		return attpost;
	}

	public void setAttpost(BbsPost attpost) {
		this.attpost = attpost;
	}

	public String getFilename() {
		return filename;
	}

	public void setFilename(String filename) {
		this.filename = filename;
	}

	public int hashCode()
	{
		return new HashCodeBuilder().append(getId()).toHashCode();
	}

	public int getDelmark() {
		return delmark;
	}

	public void setDelmark(int delmark) {
		this.delmark = delmark;
	}

	public String toString()
	{
		return new ToStringBuilder(this).append("id", getId()).toString();
	}

	public boolean equals(Object other)
	{
		if (this == other)
		{
			return true;
		}
		if (!(other instanceof BbsAttachment))
		{
			return false;
		}
		BbsAttachment castOther = (BbsAttachment) other;
		return new EqualsBuilder().append(this.getId(), castOther.getId()).isEquals();
	}

}
